package designpatterns.strategy.code;

import java.util.HashMap;
import java.util.Map;

/**
 * 带自动注册的工厂
 */
public class StrategyFactory {
    private static final Map<String,Strategy> strategyMap = new HashMap<>();


    /**
     * 通过名字获取策略
     *
     * @param strategyName
     */
    public static Strategy getStrategy(String strategyName) {
        return strategyMap.get(strategyName);
    }

    /**
     * 注册策略
     *
     * @param strategyName
     * @param strategy
     */
    public static void register(String strategyName,Strategy strategy) {
        System.out.println(String.format("=====>注册策略 strategyName=%s,strategy=%s", strategyName,strategy));
         strategyMap.put(strategyName,strategy);
    }




}
